'\" t
.TH NST 1 "22 November 2002" "WFDB 10.3.0" "WFDB Applications Guide"
.SH NAME
nst \- noise stress test for ECG analysis programs
.SH SYNOPSIS
\fBnst\fR [ \fIoptions\fR ... ]
.SH DESCRIPTION
\fBnst\fR adds calibrated amounts of noise from a \fInoise record\fR to ECGs
(or other signals) from a \fIclean record\fR, generating an \fIoutput
record\fR in WFDB format.  Such output records make it possible to assess the
noise tolerance of analysis programs.
.PP
\fIOptions\fR include:
.TP
\fB-a\fR \fIannotator\fR
Use \fIannotator\fR as the reference annotator for the clean record.
If the \fB-a\fR option is omitted, \fIatr\fR is used as the reference
annotator.  Reference annotations are used to determine the signal size as
part of the noise level calibration, unless the \fB-p\fR option (see below) is
used.  Reference annotations are also copied to the output record.
.TP
\fB-F\fR \fIformat\fR
Write output signals in the specified \fIformat\fR (default: 16;  for a
list of valid formats, see \fBsignal\fR(5)).
.TP
\fB-h\fR
Print a usage summary.
.TP
\fB-i\fR \fIclean-record noise-record\fR
Read ECG (or other) signals from \fIclean-record\fR, and noise from
\fInoise-record\fR.  \fBnst\fR obtains these record names interactively
if the \fB-i\fR option is omitted.
.TP
\fB-o\fR \fIoutput-record\fR
Create a record named \fIoutput-record\fR containing the input signals
and added noise.  \fBnst\fR obtains the name of the output record interactively
if the \fB-o\fR option is omitted.  If a header, signal, or reference
annotation file for \fIoutput-record\fR already exists in the current
directory, it will be overwritten.
.TP
\fB-p\fR \fIprotocol\fR
Use \fIprotocol\fR (the annotator name of an annotation file associated with
the noise record) to define how noise is to be added to the signals (see
below).  If the \fB-p\fR option is omitted, \fBnst\fR generates a protocol
annotation file.
.TP
\fB-s\fR \fISNR\fR
Set scale factors for noise such that the signal-to-noise ratio during
noisy segments of the output record is \fISNR\fR (in dB, see below).
This option is ignored if a \fIprotocol\fR is specified using \fB-p\fR.
.SS Output signal generation
If the sampling frequencies of the clean and noise records differ by
10% or more, \fBnst\fR resamples the noise record (using
\fBxform\fR(1)), producing a new noise record in the current
directory.  The name of the new record is that of the original (less
any suffix beginning with an underscore), with a suffix consisting of
an underscore followed by the sampling frequency of the new record.
For example, if \fBnst\fR is asked to use AHA DB record \fI1001\fR,
sampled at 250 Hz, and noise record \fIem\fR, sampled at 360 Hz, it
first generates a new noise record named \fIem_250\fR, sampled at 250
Hz.  If the noise record that \fBnst\fR would generate exists already,
\fInst\fR uses it without regenerating it.  \fInst\fR prints a warning if
it is necessary to resample the noise record, or to substitute a previously
resampled noise record.
.PP
Each ECG (or other) signal is paired and combined with a noise signal.  A gain
(\fIa\fR, a multiplicative scale factor) to be applied to the noise samples is
set independently for each clean signal.  If there are fewer noise signals than
ECG signals, noise signals are paired with more than one clean signal as
necessary.  For example, if there are three clean signals and two noise
signals, they are paired and combined as follows:
.br
	output signal 0 = clean signal 0 + \fIa\fR[0] * noise signal 0 + \fIb\fR[0]
.br
	output signal 1 = clean signal 1 + \fIa\fR[1] * noise signal 1 + \fIb\fR[1]
.br
	output signal 2 = clean signal 2 + \fIa\fR[2] * noise signal 0 + \fIb\fR[2]
.PP
The initial values of the gains, \fIa\fR, and offsets, \fIb\fR,
are zero for all signals (i.e., no noise is added).  In the protocol
annotation file, the \fItime\fR field of each NOTE annotation
specifies when gains are to be changed, and the \fIaux\fR field
specifies new values for the gains (in \fBscanf\fR(3) \fB%lf\fR
format, beginning with
\fIa\fR[0];
values are separated by white space within the \fIaux\fR field).  The offsets,
\fIb\fR, are recalculated at these times to cancel out step changes in signal
levels when gains are changed.  During the intervals between NOTE annotations
in the protocol annotation file, gains and offsets are fixed.
.PP
If no protocol annotation file is specified, \fBnst\fR generates one using
a standard protocol (a five-minute noise-free ``learning period'', followed
by two-minute periods of noisy and noise-free signals alternately until the
end of the clean record).  The gains to be applied during the noisy periods are
determined in this case by measuring the signal and noise amplitudes (see
\fBSignal-to-noise ratios\fR, below).
.PP
Generation of the output signals ends at the time of the last NOTE annotation
in the protocol annotation file, or at the end of the clean record, whichever
comes first.  If the noise record ends before that time, \fBnst\fR `rewinds'
the noise record to the beginning as necessary to obtain additional noise
samples.
.PP
If a non-standard protocol is needed, it is probably easiest to run \fBnst\fR
without the \fB-p\fR option to obtain a standard protocol annotation file.
The standard file can be converted to text by \fBrdann\fR(1), edited as
needed using any text editor, and converted back into annotation file format
by \fBwrann\fR(1).
.SS Signal-to-noise ratios
It is useful to characterize the noise level in a noise stress test in terms
of the signal-to-noise ratio (SNR) during the noisy segments.  SNR is commonly
expressed in decibels (dB):
.br
	\fISNR\fR = 10 log (\fIS/N\fR)
.br
where \fIS\fR is the power of the signal, and \fIN\fR is the power of the
noise.  If the \fB-p\fR option is omitted, \fBnst\fR measures \fIS\fR and
\fIN\fR, and determines gains for the noise signals such that \fISNR\fR
matches the level specified using the \fB-s\fR option (or interactively).
.PP
The major difficulty in applying such a definition to the noise stress test
is that most measurements of signal power are not particularly meaningful
when applied to the ECG.  A measurement based on mean squared amplitude, for
example, will be proportional to the square of the heart rate.  Such a
measurement bears little relationship to a detector's ability to locate QRS
complexes, which is typically related to the size of the QRS complex.  A
less significant problem is that unweighted measurements of noise power are
likely to overestimate the importance of very low frequency noise, which is
both common and (usually) not troublesome for detectors.  In view of these
issues, \fBnst\fR defines \fIS\fR as a function of the QRS amplitude,
and \fIN\fR as a frequency-weighted noise power measurement.  The
definitions of \fIS\fR and \fIN\fR have been chosen such that SNRs given for
noise stress tests will correspond roughly in terms of an intuitively
defined `signal quality' with SNRs such as those that may be encountered in
other contexts.
.PP
To determine \fIS\fR, \fInst\fR invokes \fBsigamp\fR(1) to read the
reference annotation file for the ECG record and to measure the
peak-to-peak amplitude of each of the first 300 normal QRS complexes
(in each case, by measuring the range of amplitudes during a window
from 50 ms before to 50 ms after the QRS annotation).  The largest 5%
and the smallest 5% of the measurements are discarded, and
\fBsigamp\fR estimates the peak-to-peak QRS amplitude as the mean of the
remaining 90% of the measurements.  \fBnst\fR squares this peak-to-peak
amplitude estimate and divides the result by 8 (correct for sinusoids, close
enough for these purposes) to obtain the QRS ``power'' estimate, \fIS\fR.
.PP
To determine \fIN\fR for the unscaled noise signals, \fBsigamp\fR divides the
first 300 seconds of the noise record into one-second chunks.  For each chunk,
\fBsigamp\fR determines the mean amplitude and the root mean squared
difference, \fIn\fR, between the signal and this mean amplitude.  As in the
calculation of S, the largest 5% and the smallest 5% of the 300 measurements of
\fIn\fR are discarded, and \fBsigamp\fR estimates the RMS noise amplitude as
the mean of the remaining 90% of the measurements.  \fIN\fR is the square of
this estimate; if a noise signal is scaled by a gain, \fIa\fR, then \fIN\fR is
scaled by the square of \fIa\fR.  To obtain the desired \fISNR\fR given \fIS\fR
and \fIN\fR, \fBnst\fR solves for \fIa\fR in the equation:
.br
	\fISNR\fR = 10 log (\fIS\fR/(\fIN\fR * \fIa\fR**2))
.PP
The calculations of \fIS\fR, \fIN\fR, and \fIa\fR are performed separately for
each pair of clean and noise signals.
.SS Noise records
Three noise records suitable for use with \fBnst\fR are available from
http://www.physionet.org/physiobank/database/nstdb/ and are also provided
in the \fInstdb\fR directory of the MIT-BIH Arrhythmia Database CD-ROM.  These
contain noise of the types typically observed in ECG recordings.  They were
obtained using a Holter recorder and standard electrodes for ambulatory
ECG monitoring, on an active subject.  The electrodes were placed on the
limbs in locations chosen such that the subject's ECG is not visible in the
recorded signals.  Two signals were recorded simultaneously.  Record \fIbw\fR
contains primarily baseline wander, a low-frequency signal usually caused by
motion of the subject or the leads.  Record \fIem\fR contains electrode motion
artifact (usually the result of intermittent mechanical forces acting on the
electrodes), with significant amounts of baseline wander and muscle noise as
well.  Record \fIma\fR contains primarily muscle noise (EMG), with a spectrum
that overlaps that of the ECG, but which extends to higher frequencies.
Electrode motion artifact is usually the most troublesome type of noise for
ECG analyzers, since it can closely mimic characteristics of the ECG.  For
this reason, the remaining records in the \fInstdb\fR directory consist of
noise from record \fIem\fR mixed with clean ECGs by \fBnst\fR.
.PP
Although an early version of \fBnst\fR generated the records in the
\fInstdb/old\fR directory, the signal-to-noise ratios of these records were not
determined using the definitions above.  (Unfortunately, they were not
calculated as stated in the \fIreadme.doc\fR file on the first edition CD-ROM,
either.)  Using the definitions above, the signal-to-noise ratios (in dB) for
the noisy portions of these records are as follows:
.br
.TS
center;
c c c c c c
c n n c n n.
\fIRecord\fR	\fISignal 0\fR	\fISignal 1\fR	\fIRecord\fR	\fISignal 0\fR	\fISignal 1\fR
118_02	19.79	14.38	119_02	20.31	13.79
118_04	13.77	8.36	119_04	14.29	7.77
118_06	10.25	4.84	119_06	10.76	4.25
118_08	7.75	2.34	119_08	8.27	1.75
118_10	5.81	0.41	119_10	6.33	-0.19
118_12	4.23	-1.18	119_12	4.74	-1.77
.TE
.SS Choosing `clean' records
If the goal is to assess noise robustness, `clean' records are best chosen
from among those that can be analyzed without error (or with very low error
rates).  Given such a choice, any errors observed in analysis of \fBnst\fR
output records can be attributed to the effects of the added noise, and not
to any intrinsic properties of the signals.
.SS Using \fBnst\fP output
The output records generated by \fBnst\fR may be analyzed in the same way
as the clean records from which they were obtained.  For ECG analyzers,
programs such as \fBbxb\fR(1), \fBepicmp\fR(1), \fBmxm\fR(1), and \fBrxr\fR(1)
may be useful for assessing the accuracy of analysis results.  A series of
\fBnst\fR output records with a range of signal-to-noise ratios may be used
to determine how analyzer performance varies as a function of SNR.  The
parameter of greatest interest is usually the minimum value of SNR for which
performance remains acceptable.
.PP
The standard protocol is designed to provide a fair yet difficult challenge
to most analyzers.  Segments of noise-free signals during the test period
illustrate how rapidly the analyzer recovers its ability to analyze clean
signals after having been presented with noisy signals.
.PP
Tests of multichannel analyzers should include records in which not all signals
are equally noisy.  Such records can be generated by \fBnst\fR with
appropriately constructed protocol annotation files.
.SH ENVIRONMENT
.PP
It may be necessary to set and export the shell variable \fBWFDB\fR (see
\fBsetwfdb\fR(1)).
.SH SEE ALSO
\fBbxb\fR(1), \fBepicmp\fR(1), \fBmxm\fR(1), \fBrdann\fR(1),
\fBrxr\fR(1), \fBsetwfdb\fR(1), \fBsigamp\fR(1), \fBxform\fR(1),
\fBwrann\fR(1), \fBsignal\fR(5)
.HP
Moody, G.B., Muldrow, W.K., and Mark, R.G.
A noise stress test for arrhythmia detectors.
\fIComputers in Cardiology\fR \fB11\fR:381\-384 (1984).
.SH AUTHOR
George B. Moody (george@mit.edu)
.SH SOURCE
http://www.physionet.org/physiotools/wfdb/app/nst.c
